package com.ruoyi.ams.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.ams.domain.AmsAssetInfoChange;
import com.ruoyi.ams.domain.AmsAssetInfoChangeDetail;
import com.ruoyi.ams.service.IAmsAssetInfoChangeDetailService;
import com.ruoyi.ams.service.IAmsAssetInfoChangeService;
import com.ruoyi.common.core.domain.KeyValueVo;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.security.annotation.PreAuthorize;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * 实物信息变更详情Controller
 * 
 * @author yfkj
 * @date 2022-05-16
 */
@RestController
@RequestMapping("/ams/changeDetail")
public class AmsAssetInfoChangeDetailController extends BaseController
{
    @Autowired
    private IAmsAssetInfoChangeDetailService amsAssetInfoChangeDetailService;
    @Autowired
    private IAmsAssetInfoChangeService assetInfoChangeService;

    /**
     * 查询实物信息变更详情列表
     */
    @PreAuthorize
    //@PreAuthorize(hasPermi = "ams:detail:list")
    //@ApiOperation(value = "获取实物信息变更详情列表")
    @GetMapping("/getAmsAssetInfoChangeDetailList")
    public TableDataInfo getAmsAssetInfoChangeDetailList(AmsAssetInfoChangeDetail amsAssetInfoChangeDetail)
    {
        startPage();
        List<AmsAssetInfoChangeDetail> list = amsAssetInfoChangeDetailService.selectAmsAssetInfoChangeDetailList(amsAssetInfoChangeDetail);
        return getDataTable(list);
    }


    /**
     * 获取实物信息变更详情详细信息
     */
    @PreAuthorize
    //@PreAuthorize(hasPermi = "ams:detail:query")
    @ApiOperation(value = "获取实物信息变更详情")
    @GetMapping(value = "/getAmsAssetInfoChangeDetailById")
    public AjaxResult getAmsAssetInfoChangeDetailById(@RequestParam("assetInfoChangeId") Long assetInfoChangeId)
    {
        AmsAssetInfoChange assetInfoChange = assetInfoChangeService.getById(assetInfoChangeId);
        List<AmsAssetInfoChangeDetail> changeDetails = amsAssetInfoChangeDetailService
                .list(new QueryWrapper<AmsAssetInfoChangeDetail>()
                        .eq(AmsAssetInfoChangeDetail.ASSET_INFO_CHANGE_ID, assetInfoChange.getAssetInfoChangeId()));
        return AjaxResult.success(changeDetails);
    }

    /**
     * 新增实物信息变更详情
     */
    @PreAuthorize
    //@PreAuthorize(hasPermi = "ams:detail:add")
    @Log(title = "实物信息变更详情", businessType = BusinessType.INSERT)
    //@ApiOperation(value = "新增实物信息变更详情")
    @PostMapping(value = "/addAmsAssetInfoChangeDetail")
    public AjaxResult addAmsAssetInfoChangeDetail(@RequestBody AmsAssetInfoChangeDetail amsAssetInfoChangeDetail)
    {
        return toAjax(amsAssetInfoChangeDetailService.save(amsAssetInfoChangeDetail));
    }

    /**
     * 修改实物信息变更详情
     */
    @PreAuthorize
    //@PreAuthorize(hasPermi = "ams:detail:edit")
    @Log(title = "实物信息变更详情", businessType = BusinessType.UPDATE)
    //@ApiOperation(value = "修改实物信息变更详情")
    @PostMapping(value = "/editAmsAssetInfoChangeDetail")
    public AjaxResult editAmsAssetInfoChangeDetail(@RequestBody AmsAssetInfoChangeDetail amsAssetInfoChangeDetail)
    {
        return toAjax(amsAssetInfoChangeDetailService.updateById(amsAssetInfoChangeDetail));
    }

    /**
     * 删除实物信息变更详情
     */
    @PreAuthorize
    //@PreAuthorize(hasPermi = "ams:detail:remove")
    @Log(title = "实物信息变更详情", businessType = BusinessType.DELETE)
	@GetMapping("/removeAmsAssetInfoChangeDetails")
    public AjaxResult removeAmsAssetInfoChangeDetails(@RequestParam Long[] assetInfoChangeDetailIds)
    {
        return toAjax(amsAssetInfoChangeDetailService.deleteAmsAssetInfoChangeDetailByAssetInfoChangeDetailIds(assetInfoChangeDetailIds));
    }
    @GetMapping("/getAmsAssetInfoChangeDetailNamesForSelect")
    //@ApiOperation(value = "获取实物信息变更详情名称列表用于下拉搜索")
    public AjaxResult getAmsAssetInfoChangeDetailNamesForSelect()
    {
        List<AmsAssetInfoChangeDetail> list = amsAssetInfoChangeDetailService.list();//自行加条件
        List<KeyValueVo> resultList = new ArrayList<>();
        for (AmsAssetInfoChangeDetail amsAssetInfoChangeDetail: list ) {
            KeyValueVo vo = new KeyValueVo();
            //vo.setKey(it.getId());
            //vo.setValue(it.getName());
            resultList.add(vo);
        }
        return AjaxResult.success(resultList);
    }
    /**
     * 导出实物信息变更详情列表
     */
    @PreAuthorize
    //@PreAuthorize(hasPermi = "ams:detail:export")
    @Log(title = "实物信息变更详情", businessType = BusinessType.EXPORT)
    @PostMapping("/exportAmsAssetInfoChangeDetail")
    public String exportAmsAssetInfoChangeDetail(HttpServletResponse response, AmsAssetInfoChangeDetail amsAssetInfoChangeDetail) throws IOException
    {
        List<AmsAssetInfoChangeDetail> list = amsAssetInfoChangeDetailService.selectAmsAssetInfoChangeDetailList(amsAssetInfoChangeDetail);
        ExcelUtil<AmsAssetInfoChangeDetail> util = new ExcelUtil<AmsAssetInfoChangeDetail>(AmsAssetInfoChangeDetail.class);
        util.exportExcel(response, list, "实物信息变更详情数据");
        return "";
    }

}
